const Controller = require("egg").Controller

class  ArticleController extends Controller{

  async getList(){
    let {ctx} = this,body = ctx.request.body
    try {
      ctx.validate({
        page:{type:"number",require:true,default:1},
        pageSize:{type:"number",require:true,max:30,min:5},
      })
      console.log("开始获取数据")
      // 编写service层
      let articleModel = await this.ctx.service.article.getList(body.page,body.pageSize)
      // console.log(articleModel)

      ctx.body = { msg:"success",code:0,total:articleModel.count, data:articleModel.rows,};
      
    } catch (error) {
      
    }
  }
  // 歌曲详情的获取
  async getInfo(){
    const { ctx } = this,params = ctx.params
    try {
      ctx.validate({
        id:{type:"string",require:true,default:"0"},
      },params)
      let data = await this.ctx.service.article.getInfo(params.id)
      console.log(data)
      ctx.body = { msg:"success",code:0, data};
    } catch (err) {
      console.log(err)
      ctx.body = { success: false,code:500};
      return;
    }
  }
}

module.exports = ArticleController